package edenmedical;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Monitor;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;


public class FrmVisDatiPulsossimetro implements Listener{
	private Display display;
	private Shell shell;
	private String dispositivo;
	private DeviceType deviceType;
	private Text txtOss,txtPressMin,txtPressMax,txtPulsazioni,txtOssigeno;
	private Button btnStorico,btnChiudi;
	
	
	public FrmVisDatiPulsossimetro(String dispositivo,String[] dati,final DeviceType deviceType)
	{
		this.dispositivo = dispositivo;
		this.deviceType = deviceType;
		this.display = Display.getCurrent();
		shell = new Shell(this.display);
		shell.setSize(333, 209);
		shell.setText("Misurazione " + dispositivo);
			shell.setLayout(null);
			
			Label lblData = new Label(shell, SWT.NONE);
			lblData.setBounds(10, 23, 24, 15);
			lblData.setText("Data");
			
			Text txtData = new Text(shell, SWT.BORDER);
			txtData.setBounds(114, 20, 193, 21);
			txtData.setEditable(false);
			txtData.setText(dati[0]);
		
			Label lblPeso = new Label(shell,SWT.NONE);		
			lblPeso.setBounds(10, 59, 100, 15);
			lblPeso.setText("Ossigenazione");
			txtOss = new Text(shell,SWT.BORDER);
			txtOss.setBounds(114, 56, 88, 21);
			txtOss.setEditable(false);
			txtOss.setText(dati[1]);
		
		btnStorico = new Button(shell,SWT.PUSH);
		btnStorico.setBounds(55, 137, 89, 25);
		btnStorico.setText("Mostra Storico");
		btnStorico.addListener(SWT.Selection, new Listener() {
			
			public void handleEvent(Event e) {
				FrmStoricoPulsossimetro frmStorico = new FrmStoricoPulsossimetro("Pulsossimetro",deviceType);
				frmStorico.Show();
		
			}
		});
		
		btnChiudi = new Button(shell,SWT.PUSH);
		btnChiudi.setBounds(172, 137, 88, 25);
		btnChiudi.setText("Chiudi");
		
		Label lblPressioneMinima = new Label(shell, SWT.NONE);
		lblPressioneMinima.setText("Pulsazioni");
		lblPressioneMinima.setBounds(10, 95, 100, 15);
		
		Text txtPuls = new Text(shell, SWT.BORDER);
		txtPuls.setText(dati[2]);
		txtPuls.setEditable(false);
		txtPuls.setBounds(114, 92, 88, 21);
		
		btnChiudi.addListener(SWT.Selection,this);	
	}

	public void Show(){
		shell.open();
		Monitor primary = display.getPrimaryMonitor();
	    Rectangle bounds = primary.getBounds();
	    Rectangle rect = shell.getBounds();
	    int x = bounds.x + (bounds.width - rect.width) / 2;
	    int y = bounds.y + (bounds.height - rect.height) / 2;
	    shell.setLocation(x, y);
		while( !shell.isDisposed())
		{
			if(!display.readAndDispatch())
				display.sleep();
		}
	}

	public void handleEvent(Event e) {
		if (e.widget.equals(btnChiudi))
		{
			shell.dispose();
		}
	}
}
